package GJAM.SAMPLE.Calculator.Tests;

import GJAM.SAMPLE.Calculator.*;
import jmunit.framework.cldc11.*;

public class CalculatorModelTest extends TestCase {

    public CalculatorModelTest() {
        super(1, "CalculatorModelTest");
    }

    public void test(int testNumber) throws Throwable {
        switch (testNumber) {
         
            case 0:
                testCalculate();
                break;
            default:
                break;
        }
    }

    public void testCalculate() throws AssertionFailedException {
        System.out.println("Calculate");
        CalculatorModel instance = new CalculatorModel();
        
        Calculate(instance, 4, 2, "+", 2);
        Calculate(instance, -4, -2, "+", -2);

        Calculate(instance, 25, 5, "*", 5);
        Calculate(instance, 6, 2, "*", 3);

        Calculate(instance, 5, 25, "/", 5);
        Calculate(instance, 8, 40, "/", 5);

        Calculate(instance, 0, 25 , "-", 25);
        Calculate(instance, -25, 50, "-", 75);
    }

    private void Calculate(CalculatorModel instance, int expectedResult, int op1, String operator, int op2) throws AssertionFailedException {
        instance.Calculate(op1, operator, op2);
        int result = instance.getResult();
        String message = "Calculation failed for : " + String.valueOf(op1) + " " + operator + " " + String.valueOf(op2);
        assertEquals(message,expectedResult, result);
    }
}
